import java.util.Stack;

public class MyQueue {
    //两个栈组成一个队列
    //队列其实就是一种集合
    public static void main(String[] args) {
      /*  Queue<Integer> queue =new ArrayDeque<>();
        queue.add(1);
        queue.add(2);
        System.out.println(queue);
        queue.poll();
        System.out.println(queue);*/
        MyQueue myQueue = new MyQueue();
        myQueue.add(1);
        myQueue.add(2);
        myQueue.add(3);
        System.out.println(myQueue);
        myQueue.poll();
        System.out.println(myQueue);
    }
    Stack<Integer> stack1;
    Stack<Integer> stack2;

    public MyQueue() {
        stack1 =new Stack<Integer>();
        stack2 =new Stack<Integer>();
    }
    public void add(int a){
        stack1.push(a);
    }

    public int poll(){
        if (stack1.isEmpty()&&stack2.isEmpty()){
            return -1;
        }
        if (stack2.isEmpty()){
            while (!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
            return stack2.pop();
        }
        return stack2.pop();
    }

    public int peek(){
        if (stack1.isEmpty()&&stack2.isEmpty()){
            return -1;
        }
        if (stack2.isEmpty()){
            while (!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
            return stack2.peek();
        }
        return stack2.peek();
    }

    @Override
    public String toString() {
        return "MyQueue{" +
                "stack1=" + stack1 +
                ", stack2=" + stack2 +
                '}';
    }
}
